package algorithmTopics.array;

public class test3 {

    public static void main(String[] args) {
        test3 test3 = new test3();
        int[] nums=  {1,2,3,4,5,6,7};
        test3.rotate(nums,10);
        //System.out.println(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] +",");
        }
    }

    public void rotate(int[] nums, int k) {

        if(k == nums.length){
            ;
        } else {
            k =  k % nums.length;
            int[] temp = new int[k];
            //把前面的个数依次移动到后面，再把后面的重新装入前面
            //取出后面的数字
            for (int i = 0; i < k; i++) {
                temp[i] = nums[nums.length - 1 - i];
            }
            //移动前面到后面
            for (int i = 0; i < nums.length- k; i++) {
                nums[nums.length - 1 - i] = nums[nums.length - k - i -1];
            }
            //把存的读取
            for (int i = 0; i < k; i++) {
                nums[k - i - 1] = temp[i];
            }


        }
    }


}
